package main;

import java.io.*;

import domainModel.*;

public class Main {

	public static void main(String[] args) {

		Forest padure = new Forest();

		// Node root = new Node("root",null,"root","Earth");
		Node a = new Node("A", null, "arb1");
		Node b = new Node("B", a, "arb1");
		Node c = new Node("C", a, "arb1");
		Node d = new Node("D", c, "arb1");

		Node e = new Node("E", null, "arb2");
		Node f = new Node("F", e, "arb2");

		Node g = new Node("G", null, "arb3");

		padure.addNode(a);
		padure.addNode(b);
		padure.addNode(c);
		padure.addNode(d);
		padure.addNode(e);
		padure.addNode(f);
		padure.addNode(g);

		for (Node temp : padure.getForest()) {
			System.out.println(temp.toString());
		}

		System.out.println();

		/** Scriem Forest in fisier */
		try (ObjectOutputStream obj_out = new ObjectOutputStream(
				new FileOutputStream("forest"))) {

			obj_out.writeObject(padure);
		} catch (IOException ex) {

			ex.printStackTrace();
		}

		Forest readPadure = new Forest();

		/** Citim Forest din fisier */
		try (ObjectInputStream obj_in = new ObjectInputStream(
				new FileInputStream("forest"))) {

			System.out.println("Acuma am citit din fisier\n");
			readPadure = (Forest) obj_in.readObject();

		} catch (IOException ex) {
			ex.printStackTrace();
		} catch (ClassNotFoundException ex) {

			ex.printStackTrace();
		}

		for (Node temp : readPadure.getForest()) {
			System.out.println(temp.toString());
		}

	}

}
